Index News | Section 8






Various

Remove a line from Autoexec.bat Find RAMDRIVE Compare files Create a directory with the computer date. (Correspondence) Input to all those poor NT users. (includes an Qbasic file) Searching for a word Current drive Filename without an extension Take off Number.bat
Subject: Remove a line from Autoexec.bat Sent: January 07, 2000 Newsgroups: alt.msdos.batch @Echo off Set A= Attrib C:\AUTOEXEC.BAT | Find "R" > NUL If not errorlevel 1 Set A=-R Attrib C:\AUTOEXEC.BAT | Find "H" > NUL If not errorlevel 1 Set A=%A% -H Attrib %A% C:\AUTOEXEC.BAT > NUL Find /i /v "Text to be deleted.." < C:\AUTOEXEC.BAT > C:\A Move /y C:\A C:\AUTOEXEC.BAT > NUL Echo %A%| Find "R" > NUL If not errorlevel 1 Attrib +R C:\AUTOEXEC.BAT Echo.%A%| Find "H" > NUL If not errorlevel 1 Attrib +H C:\AUTOEXEC.BAT Set A=
:: Find RAMDRIVE :: OS. Win98 :: Date: April 21, 2000 :: Author: Benny Pedersen @Echo off If not %2'==' Goto CALL_2 If not %1'==' Goto CALL_1 Rem >%temp%.\label.scr For %%v in (. .n) do Echo%%v>> %temp%.\label.scr For %%v in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do Call %0 %%v Goto END :CALL_1 Label %1:<%temp%.\label.scr |Find "RAMDRIVE">Nul If errorlevel 1 Goto EOF :END For %%p in (Cls Echo. Echo.˙RAMDRIVE˙is˙%1) do %%p If %1'==' Echo * Not found. * For %%c in ("Del %temp%.\label.scr" Echo.) do %%c If %1'==' For %%c in (Pause Cls Exit) do %%c Echo Press Escape or the drive letter that you want to assign %1:\Temp? Echo Press a key for an existing virtual drive letter to remove it. Choice/CABCDEFGHIJKLMNOPQRSTUVWXYZ/N If errorlevel 27 For %%c in (Cls Exit) do %%c For %%c in ("Set R=%1" "Set X=" Cls) do %%c :: --- ONE LINE: %0 1 A 2 B 3 C 4 D 5 E 6 F 7 G 8 H 9 I 10 J 11 K 12 L 13 M 14 N 15 O 16 P 17 Q 18 R 19 S 20 T 21 U 22 V 23 W 24 X 25 Y 26 Z 27 :CALL_2 --------------------------------------- If errorlevel %1 If not errorlevel %3 Set X=%2 For %%c in (1 2) do Shift If %X%'==' Goto CALL_2 ------------------------ If exist %X%:\Nul For %%c in ("SUBST/d %X%:" "Set R=" "Set X=" Exit) do %%c If not exist %R%:\Temp\Nul For %%c in (%R%: Md\Temp) do %%c For %%c in ("SUBST %X%: %R%:\Temp" "Set R=" "Set X=" Exit) do %%c :EOF
* Compare files The following updated batchfile is from "my old Homepage". OOPS: The latest version can be found here: "News page 6". This new one is more optimized, but it's language sensitive (see the comment:) @Echo off If %1'==' Goto Msg For %%E in (: d) do C%%E %TEMP%\ If exist Equal.bat For %%E in (Call Del Goto) do %%E Equal.bat Echo Set Equal=%1> Equal.bat For %%E in (Cls Exit) do %%E :Equal For %%E in (%Equal% %1) do Echo -----%%E Fc/b %Equal% %1|Find "no differences ">Nul :: Fc/b %Equal% %1|Find "ingen forskelle">Nul If errorlevel 1 Echo *NOT* Set Equal= For %%E in (Echo "Pause|Nul" Cls Exit) do %%E Equal :Msg Echo Win9x - Compare two files. Drag & drop a file to the Echo icon of Equal.bat, then drag & drop the second file. Echo. If %0==%TEMP%\EQUAL.BAT Echo But first you must move %TEMP%\Equal.bat If %0==%TEMP%\EQUAL.BAT Echo 2 another location than %TEMP%\ * Tips: On your Desktop, Copy & Paste this good freeware program into a new batch file. * Note: Updated April 18, 2000: Equal.zip (not language sensitive)
* Md %date% (Correspondence) > I'm trying to make a batch file that would create a directory with the > computer date, and then save a file to that directory it just created. > I tried md %date% with no luck, any ideas? > > (Microsoft Certified Professional System Engineer, Bell Canada (ICS)). * Hmmm - How about this one? :: Date: May 11, 2000. :: Author: B.Pedersen. :: @Echo off if %WINdir%!==! Echo This program requires Microsoft Windows. if %WINdir%!==! Goto End :: --- ONE LINE: %comspec%/c For %%v in (1 2) do Prompt If %%3!==! %%0 $d monkey_ass $_c:$_c d\$_if not exist ~Date\NUL MD ~Date$_CD ~Date$_if exist %%2\NUL Echo Directo ry exist: %%2$_if exist %%2\NUL Choice Continue $_if exist %%2\NUL if errorl evel 2 Goto N$_MD %%2$_Explorer \~Date$_:N$_|Find/v "$">%temp%.\Date-Dir.bat For %%c in (Cal De) do %%cL %temp%.\Date-Dir.bat Rem pfe32 %0 %temp%.\Date-Dir.bat :: $_if %%WINdir%%!==! DIR/P/W/AD/OD \~Date :End
* QBasic Example (Get input. DOS/Win9x/NT) Someone wrote: > I am trying to program an installation batch file using > the command Choice. I'm writing for a WinNT, 98, 95 OS, > and I see that Choice is not a recognized command word? :: Microsoft don't permit you to use the CHOICE command... :: but maybe something like this? @Echo off Echo OPEN "%temp%\~c.bat" FOR OUTPUT AS #1> %temp%\~c.bas Echo INPUT "Enter your input: ", in$>> %temp%\~c.bas Echo PRINT #1, "set in="; in$>> %temp%\~c.bas Echo CLOSE #1>> %temp%\~c.bas Echo SYSTEM>> %temp%\~c.bas Qbasic /run %temp%\~c.bas Call %temp%\~c.bat Echo. Echo. Your input was: %in% Echo. Pause Cls Set in= Del %temp%\~*
* Searching for a word Someone wrote: > I was wondering if it's possible for a batchfile to read > another txt file, searching for a word. And when it's in > the file to implemend it into the batchfile. For example > > You can think of a homework test that a student did, and > the teacher is tired of typing the name everytime. So in > the test the student has written his/her name. > Behind a field where it sais:'Type here your name ....'. > The batch file is to search for that name and when it is > found it puts that name in another txt file to see which > students did deliver their homework to the teacher. @Echo off :: Create some test files (3 files) For %%c in (ls : d) do C%%c \ If not exist Biology\NUL Md Biology Cd Biology If not exist Sex_Edu\NUL Md Sex_Edu Cd Sex_Edu If not exist MyClass\NUL Md MyClass Cd MyClass Echo your name here: Benny >>A.txt Echo your name here: bill >>B.tmp Echo your name here: Tom L.>>C.htm :: Define an environment variable named "Name" + Ask for the students name: Cd %temp%\ Echo Set Name=> ~Name Echo l102>~CRLF For %%v in (w f100LFF''1A l w102 q) do Echo %%v>> ~CRLF Debug ~Name<~CRLF > NUL Echo When finished your input: Press [F6] then [Enter]. What name: (Bill)? Copy ~Name + CON ~Name > NUL For %%f in (Move Call) do %%f ~Name ~Name.bat > NUL For %%f in (Name.bat CRLF) do Del ~%%f :: She pressed [F6] and [Enter]. The teacher is now searching in her files: Rem Wondering I could help her - ARGH! Echo Name is (%Name%). Search all files (C:\Biology\Sex_Edu\MyClass)>>~Name For %%c in (\Biology\Sex_Edu\MyClass\*.*) do Find/i/c ": %Name%" %%c>>~Name Type ~Name| Find/v ": 0" | Find/i "\MyClass\" If errorlevel 1 Echo That name: (%Name%) was not found! If errorlevel 1 Del ~Name For %%c in ("Set Name=" Echo. Echo. Echo. Pause) do %%c If exist ~Name. If exist "%windir%\Notepad.exe" Notepad ~Name. Rem|Choice/C˙/N/T˙,02<NUL Deltree C:\Biology If exist ~Name. Del ~Name Cls : Read more correspondence
* Filename without an extension I end up with a text file that has a version number in it. This version number changes periodically. When you type the text file, it reads like this: 0d.ver I need to extract the "0d" from above and put it at the end of a line in a INI file, like so: SDB_version=0d This would be fun if I wasn't under pressure. Thank you for any help/suggestions! Jerry J. Davis @Echo off If %2'==' Exit If exist %temp%\_#_\NUL For %%c in ( Echo Exit ) do %%c.%temp%\_#_\ Echo.SDB_version= >> %2 Rem >> %1 For %%v in (Md Copy:%1+%2 Cd) do %%v %temp%\_#_ > NUL Ren * * For %%v in (*) do set v=%%v Find/v "SDB_version="< %2 > %v% Type %v% > %2 Echo.SDB_version=%v%>> %2 For %%v in ( Del:%v% "Set v=" Cd.. Rd:_#_ Cls) do %%v Exit. Here's another version: @Call Longfi~1 "%windir%\test\12345678 90 1234d.ver" "\s o m e.ini" Exit "Call it.bat" @Echo %[ Long filenames on]%off If %2'==' Exit this file, which I used to write the second file %2; :: SDB_version="the filename of %1 (without the .Extension)" If exist %temp%\_#_\NUL For %%v in ( Echo Exit ) do %%v.%temp%\_#_\ Echo.SDB_version= >> %2 :: Omit the above line is ok, if you remove the "+%2", (see later:) Rem >> %1 :: If %1 can be a zero-byte file, then you must keep :: the "+%2" as in the second line: Copy %1+%2 For %%v in (Md Cd) do %%v %temp%\_#_ Copy %1+%2 > NUL Ren * * LfnFor:on For %%v in (*) do set v=%%v Find "SDB_version="/v< %2 >"%v%" Echo.SDB_version=%v%> %2 Type "%v%">> %2 For %%v in ( "Set v=" LfnFor:off Cd.. "Deltree/y _#_ > NUL") do %%v
Lfnfor @ for %%e in ( :off . .˙˙˙files: .) do echo%%e for %%f in (*.*) do echo %%f echo. echo. Below you'll see the same as above, (except filenames is long:) for %%e in (:on :off . .˙˙˙files: .) do echo%%e Lfnfor on for %%f in (* ) do echo %%f for %%c in (Lfnfor:off echo.) do %%c
How do I truncate file names to the underscore so that a directory of files in the following format: 1234567_123.txt 123456789012_12.txt become: 1234567_xx_xx_xx 123456789012_xx_xx_xx Can this be done in one operation? -- Thanks in advance. @if not (%1)==() goto TAKE off now! if called from it self, (see [L17]) @choice Shall I make some test files for you: @if errorlevel 2 goto TAKE off @rem > 10-------_------------------------.txt @rem > 30---------------------------_----.txt pause. :TAKE off %[L09]% for %%v in ( echo cls set REM: GOTO) do %%v off=%1 echo. _________1_________2_________3_________4_________5_________6____ echo. 1234567890123456789012345678901234567890123456789012345678901234 for %%v in (echo pause) do %%v. ?%1 %{-- You can erase these --% :OFF -- lines or substitute REM: GOTO) with REM:GOTO ), see [L09] --} %[L16]% if exist ?%off%_*.txt rename %off%?_*.txt %off%?_xx_xx_xx. %[L17]% if exist *_*.txt for %%v in ( set call ) do %%v off=?%off% %[L18]% for %%v in (set pause cls exit. Take off, bye-bye ;) do %%v off= Comments: --------- %0: If you instead of "off.bat", named this file "ufo.bat", then you L17, L09: must substitute (call) with ("call ufo") and (%1) with (%2).
* Current drive @ %COMSPEC%/C For %%v in (1 2) do Prompt Current drive is $n$_|Find/v "_" @ Exit @ Echo off @ Cd %temp%\ Find/v "@" < %0 | Debug > NUL :: For %%c in (plorer it @) do Ex%%c %temp% @ For %%c in (" " Echo.˙says Rem.Pause "Erase/p" Cls Exit) do %%c Drive.com @ N Drive.com E 100 B4 09 BA 14 01 CD 21 B4 19 CD E 10A 21 04 41 88 C2 B4 02 CD 21 C3 E 114 "---- Current drive is $" RCX 2C W Q
* Number.bat @echo off if ::==%4 goto p rem %0 Start End Digit :: set d=::|%comspec%/e:2048/c %0 007 021 ### :: for %%v in (set pause cls goto:eof) do %%v d= :p if %3==%5 goto x for %%. in (0 1 2 3 4 5 6 7 8 9) do call %0 %1 %2 %3 %4 %5# %6%%. goto eof :x if %1==%6 set d= :: if ::==%d% goto eof (The program goes in the following line:) %d% echo %6. if %2==%6 exit. :eof Jump to updated stuff (includes a description:) click here.
Under construction. Number.bat and Traffic.bat: You can ignore this old stuff. I wrote it before I joined the committee and learned the batch language. @if ::::::==%1 goto Number @if '=='%1 goto Run Once :Continue call traffic 0 count for %%i in ( 0 1 2 3 4 5 6 7 8 9 ) do if not errorlevel 1 call %0 %1:: %2 % 3 %%i %1 for %%v in (start end do number) do set %%v= %1 traffic goto End_Of_File :Run Once @%1echo off call traffic 1 count %1 for %%v in (start end) do set %%v=0 :Choose_Start %1 choice/n/c1234567890- (Start)=(%start%). Choose the value of start, - m inus to continue... %1 if 0==%start% set start= %1 if not errorlevel 10 for %%i in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %% i set start=%start%%%i %1 if errorlevel 10 if not errorlevel 11 set start=%start%0 %1 for %%v in (cls if:not) do %%v errorlevel 11 goto Choose_Start %1 if errorlevel 12 for %%v in (set: goto:Choose_) do %%vstart=0 %1 if '==%start%' set start=0 %1 echo. :Choose_End %1 choice/n/c1234567890- (Start)=(%start%). (End)=(%end%). Choose the valu e of end, - minus to continue... %1 if 0==%end% set end= %1 if not errorlevel 10 for %%i in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %% i set end=%end%%%i %1 if errorlevel 10 if not errorlevel 11 set end=%end%0 %1 for %%v in (cls if:not) do %%v errorlevel 11 goto Choose_End %1 if errorlevel 12 for %%v in (set: goto:Choose_) do %%vend=0 %1 if '==%end%' set end=0 %1 set do=:: %1 fc nul nul > nul goto Continue :Number call traffic 2 count set number=%2%3%4 if %2==0 set number=%3%4 if %2%3==00 set number=%4 if %start%==%number% set do= %do% echo %number% if %end%==%number% fc nul > nul :End_Of_File Traffic.bat: @echo off goto %2! :count! if exist %temp%.\Writ.com goto Write Echo N %temp%.\Writ.com> %temp%.\Writ.scr Echo A 100>> %temp%.\Writ.scr For %%v in ("MOV BX, 80" "INC BX" "CMP BYTE [BX], D" ) do Echo %%v>>%temp%. \Writ.scr For %%v in ("JNE 103" "MOV BYTE [BX], 24" "MOV AH, 9") do Echo %%v>>%temp%. \Writ.scr For %%v in ("MOV DX,82" "CMP DX,BX" "JG 117" "INT 21") do Echo %%v>>%temp%. \Writ.scr For %%v in (."MOV AH, 4C" ."INT 21" . .RCX .1B .W .Q ) do Echo%%v>> %temp%. \Writ.scr Echo.>%temp%.\Writ.com Debug %temp%.\Writ.com < %temp%.\Writ.scr > NUL Erase %temp%.\Writ.scr :Write set e= if not errorlevel 1 set e=0 %temp%.\Writ.com %1>> %temp%.\%1.tmp if 0==%e% fc nul nul> nul for %%v in (set goto:End) do %%v e= :! if exist %temp%.\*.tmp goto N echo Usage: call traffic ID-Number count echo. echo Example: call traffic 00 count echo call traffic 14 count echo traffic :N rem > %temp%.\q.bat for %%v in (0 1 2 3 4 5 6 7 8 9 00 01 02 03 04 05 06 07 08 09 10 11 12 13 1 4) do if exist %temp%.\%%v.tmp call %0 %%v X for %%v in (call del) do %%v %temp%.\q.bat echo. for %%v in (if pause cls goto:End) do %%v exist %temp%.\*.tmp del %temp%.\* .tmp :X! %temp%.\Writ.com call %0 >> %temp%.\q.bat dir %temp%.\%1.tmp | find " TMP " >> %temp%.\q.bat goto End :TMP! echo Traffic %1: %3 times. :End
Use the back button in your browser, if you are redirected to this place. The WHAT.EXE file is on "my old Homepage". :: Free disk space What K c Echo Free disk space on drive C: [%what%] Mb. :: File size What F filename Echo [%what%] Kb
-Top- News | Section 8